import java.util.Map;
import java.util.List;

/**
* ${classInfo.classComment}
* @author ${authorName}
* @date ${.now?string('yyyy/MM/dd')}
*/
@Service
@Slf4j
public class ${classInfo.className}ServiceImpl extends BaseService implements I${classInfo.className}Service{
@Autowired
private ${classInfo.className}Dao dao;

@Override
public void creation(${classInfo.className}ListForm form) {
List<${classInfo.className}DO> dos = form.getForm().stream().map(item -> Copier.copy(item, new ${classInfo.className}DO())).collect(Collectors.toList());
    for (${classInfo.className}DO item : dos) {
    setBaseInfoData(item);
    }
    dao.batchInsert(dos);
    }

    @Override
    public void update(${classInfo.className}ListForm form) {
    List<${classInfo.className}DO> dos = form.getForm().stream().map(item -> Copier.copy(item, new ${classInfo.className}DO())).collect(Collectors.toList());
        for (${classInfo.className}DO item : dos) {
        setUpateName(item);
        }
        dao.batchUpdate(dos);
        }

        @Override
        public PaginationInfo<${classInfo.className}Dto> query(${classInfo.className}PageForm form) {
            /** 查询操作 */
            PaginationInfo<${classInfo.className}Dto> result = new PaginationInfo<>();
                // 设置年度区划查询条件
                setBaseSearchInfo(form);
                // 转换排序条件
                String orderBy = ComponentUtils.assembleOrderInfo(form.getOrderList(), form);
                form.setOrderBy(orderBy);
                if (form.getIsAllData() != null && form.getIsAllData().equals(YesOrNoIntegerEnum.YES.getCode())) {
                // 查库操作
                List<${classInfo.className}DO> query = dao.query(form,form.getEw(), form.getOrderBy());
                result.setPageInfo(BasConstant.INT_ONE, query.size(), query.size());
                    //返回实体封装
                    result.setCurrentPageResult(query.stream().map(item-> Copier.copy(item,new ${classInfo.className}Dto())).collect(Collectors.toList()));
                    return result;
                    } else {
                    // 组装分页信息
                    Page<?> page = PageUtil.startBizPage(form, form.getOrderBy(), null);
                    // 查库操作
                    List<${classInfo.className}DO> query = dao.query(form,form.getEw(), form.getOrderBy());
                        result.setPageInfo(form.getPageNumber(), form.getPageSize(), page.getTotal());
                        page.close();
                        //返回实体封装
                        result.setCurrentPageResult(query.stream().map(item-> Copier.copy(item,new ${classInfo.className}Dto())).collect(Collectors.toList()));
                        return result;
                        }
                    }

                    @Override
                    public ${classInfo.className}Dto detail(Long id) {
                    ${classInfo.className}DO result = dao.findById(id);
                    return  Copier.copy(result,new ${classInfo.className}Dto());
                    }

                    @Override
                    public void delete(Long id) {
                    ${classInfo.className}DO param = new ${classInfo.className}DO();
                    param.setId(id);
                    dao.delete(param);
                    }

                    @Override
                    public List<${classInfo.className}Dto> queryList(${classInfo.className}PageForm form) {

                        /** 查询操作 */
                        // 设置年度区划查询条件
                        setBaseSearchInfo(form);
                        // 转换排序条件
                        String orderBy = ComponentUtils.assembleOrderInfo(form.getOrderList(), form);
                        form.setOrderBy(orderBy);
                        // 查库操作
                        List<${classInfo.className}DO> query = dao.query(form,form.getEw(), form.getOrderBy());
                            return query.stream().map(item-> Copier.copy(item,new ${classInfo.className}Dto())).collect(Collectors.toList());
                            }

                            public static void setBaseInfoData(BaseDO baseDO) {
                            Date date = DateUtils.now();
                            HeaderDto header = HttpHeaderUtils.getRequestHeader();
                            String divCode = EmptyChecker.isEmpty (header.getDivCode ()) ? header.getTenantId () : header.getDivCode ();
                            baseDO.setMofDivCode(divCode);
                            baseDO.setFiscalYear(header.getFiscalYear());
                            baseDO.setCreateTime(new Date());
                            baseDO.setCreateById(header.getUserId() != null ? header.getUserId() : "-1");
                            baseDO.setCreateBy(header.getUserName() != null ? header.getUserName() : "-1");
                            baseDO.setUpdateTime(baseDO.getCreateTime());
                            baseDO.setUpdateById(header.getUserId() != null ? header.getUserId() : "-1");
                            baseDO.setUpdateBy(header.getUserName() != null ? header.getUserName() : "-1");
                            baseDO.setIsDeleted(BasConstant.INT_ZERO);
                            baseDO.setVer(BasConstant.INT_ONE);
                            baseDO.setVersion(StringUtils.EMPTY);
                            baseDO.setVersionName(StringUtils.EMPTY);
                            baseDO.setEleVersion(BasConstant.STRING_ZERO);

                            }

                            public static BaseDO setUpateName(BaseDO baseDO) {
                            HeaderDto header = HttpHeaderUtils.getRequestHeader();
                            baseDO.setUpdateTime(baseDO.getCreateTime());
                            baseDO.setUpdateById(header.getUserId());
                            baseDO.setUpdateBy(header.getUserName() != null ? header.getUserName() : "-1");
                            return baseDO;
                            }


                            public static BaseForm setBaseSearchInfo(BaseForm form) {
                            HeaderDto header = HttpHeaderUtils.getRequestHeader();
                            if (EmptyChecker.isEmpty(form.getMofDivCode())) {
                            form.setMofDivCode(header.getDivCode());
                            }
                            if (EmptyChecker.isEmpty(form.getFiscalYear())) {
                            form.setFiscalYear(header.getFiscalYear());
                            }
                            return form;
                            }
                            }